GtkListBox: Improve focus scrolling
authorMatthias Clasen <mclasen@redhat.com>
Mon, 20 Jul 2015 02:18:58 +0000 (22:18 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 20 Jul 2015 02:18:58 +0000 (22:18 -0400)
We are trying to scroll the header in view together with the
focus row. The way this is implemented works fine when scrolling
up, but falls short when scrolling down. Fix this by making sure
that both the row and the header bar visible.

gtk/gtklistbox.c

index 522e91f1eb4855e5911333c0790da11829d2a42e..2aa372b16972a9cb1af748b4d2dc50909511be1b 100644 (file)
@@ -1425,21 +1425,26 @@ ensure_row_visible (GtkListBox    *box,
 {
   GtkListBoxPrivate *priv = BOX_PRIV (box);
   GtkWidget *header;
-  GtkWidget *widget;
+  gint y, height;
   GtkAllocation allocation;
 
   if (!priv->adjustment)
     return;
 
+  gtk_widget_get_allocation (GTK_WIDGET (row), &allocation);
+  y = allocation.y;
+  height = allocation.height;
+
   /* If the row has a header, we want to ensure that it is visible as well. */
   header = ROW_PRIV (row)->header;
   if (GTK_IS_WIDGET (header) && gtk_widget_is_drawable (header))
-    widget = header;
-  else
-    widget = GTK_WIDGET (row);
+    {
+      gtk_widget_get_allocation (header, &allocation);
+      y = allocation.y;
+      height += allocation.height;
+    }
 
-  gtk_widget_get_allocation (widget, &allocation);
-  gtk_adjustment_clamp_page (priv->adjustment, allocation.y, allocation.y + allocation.height);
+  gtk_adjustment_clamp_page (priv->adjustment, y, y + height);
 }
 
 static void